package logic

import (
	"context"
	"xialou_platform/app/requestx"
	"xialou_platform/services/agent/rpc/agentClient"

	"xialou_platform/services/agent/api/internal/svc"
	"xialou_platform/services/agent/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AgentUserUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAgentUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) AgentUserUpdateLogic {
	return AgentUserUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AgentUserUpdateLogic) AgentUserUpdate(req *types.AgentUserUpdateReq) error {
	uid, err := requestx.FetchUserIdByJwt(l.ctx)
	if err != nil {
		return err
	}
	agentParam, err := l.svcCtx.AgentRpc.AgentById(l.ctx, &agentClient.IdBody{Id: uid})
	if err != nil {
		return err
	}
	agentParam.Avatar = req.Avatar
	agentParam.Gender = req.Gender
	_, err = l.svcCtx.AgentRpc.AgentUpdate(l.ctx, agentParam)
	if err != nil {
		return err
	}
	return nil
}
